import { login, logout, getUserInfo } from '@/api/base/Base'
import router from '@/router'

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      userInfo: {} as UserInfo
    }
  },
  getters: {},
  actions: {
    async Login(username: string, password: string) {
      const { data } = await login(username, password)
      setUserId(data)
      router.push({ path: _ViewPath.Home })
    },
    async Logout() {
      await logout(getUserId()!)
      removeUserId()
      removeRoleId()
      removeSystemTags()
      useTagStore().InitTags()
      router.push({ path: _ViewPath.Login })
    },
    async InitUserInfo() {
      const { data } = await getUserInfo()
      this.userInfo = data
    }
  }
})
